package tech.aistar.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 本类用来演示: 支持http协议
 *
 * @author: success
 * @date: 2021/4/15 10:30 上午
 */
@WebServlet(urlPatterns = "/day01/http")
public class HttpServletDemo extends HttpServlet {

//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("get...");
//    }
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       this.doGet(req,resp);
//    }


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 设置文档类型
        resp.setContentType("text/html;charset=utf-8");
        //2. 获取文档输出流
        PrintWriter out = resp.getWriter();
        //3. 输出页面
        out.println("<!doctype html>");
        out.println("<html>");
        out.println("   <head>");
        out.println("       <meta charset='utf-8'>");
        out.println("       <title>上古时代</title>");
        out.println("   </head>");
        out.println("   <body><h3>servlet程序</h3></body>");
        out.println("</html>");
    }
}
